package cn.ly.sentinel;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;


//哨兵原生代码
public class TestSentinel {


    public static void main(String[] args) {

        testSentinelaaa();
    }

    public static void testJedis(){
        Jedis jedis =new Jedis("192.168.18.128",6379);
//        jedis.auth("xxxx"); //如果Redis服务连接需要密码，制定密码
        String value = jedis.get("name"); //访问Redis服务
        System.out.println(">>>>>>>>Value:"+value);
        jedis.close(); //使用完关闭连接
    }

    public static void testSentinelaaa(){
        String   masterName = "mymaster";
        Set<String> sentinels = new HashSet<>();
        sentinels.add("192.168.18.128:26379");
        sentinels.add("192.168.18.128:26389");
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(5);
        config.setMaxTotal(20);
        JedisSentinelPool pool = new JedisSentinelPool("mymaster", sentinels, config);
        Jedis jedis = pool.getResource();
        jedis.set("springBoot", "hhahahah");

        jedis.close();
        pool.close();
    }
}
